#!usr/bin/env python
# -*- coding:utf-8 _*-
"""
@author:zhengxin
@file: 034_odd_number.py
@time: 2024/12/24  13:49
# @describe:
"""

"""
    题目：求0—7所能组成的奇数个数。

"""
from math import factorial


# 计算排列数 P(n, r)
def permutation(n, r):
    return factorial(n) // factorial(n - r)


def count_odd_numbers():
    total_count = 0
    digits = [0, 1, 2, 3, 4, 5, 6, 7]
    odd_digits = [1, 3, 5, 7]

    for length in range(1, len(digits) + 1):
        if length == 1:
            # 单位数，只有奇数
            total_count += len(odd_digits)
        else:
            # 个位为奇数，其它位置从剩余数字中排列
            total_count += len(odd_digits) * permutation(len(digits) - 1, length - 1)

    return total_count


# 输出结果
print("0-7能组成的奇数个数为：", count_odd_numbers())
